<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2020/7/14
  Time: 14:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8 ? MYOA_CHARSET : htmlspecialchars($HTML_PAGE_CHARSET))?>" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css?20190817.1">
    <link rel="stylesheet" href="/lib/layui/layui/css/common.css">
    <link rel="stylesheet" href="/lib/layui/layui/css/eleTree.css">
    <script type="text/javascript" src="/js/jquery/jquery-1.9.1.js"></script>
    <script src="/lib/layui/layui/layui.js"></script>
    <script src="/lib/jquery.form.min.js"></script>
    <script src="/lib/layui/layui/js/common.js?v=20190726" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layui/layui/js/baseCode/base.js?v=2019080918:09" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/lib/layui/layui/global.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <style>
        .content{
            width: 50%;
            border: 1px solid #9E9E9E;
            padding: 20px;
            margin: 0 auto;
            margin-top: 20px;
        }
        .layui-form{
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
        }
        .btn{
            margin-top: 10px;
        }
        .btn>button{
            background: #2F8AE3;
            border-radius: 6px;
        }
        #duplication{
            cursor: not-allowed;
        }
    </style>
</head>
<body>
    <div class="content">
        <form class="layui-form" action="" lay-filter="example" class="ajaxform">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label"><span style="color: red;">*</span>合同名称：</label>
                    <div class="layui-input-inline" style="width: 250px;margin-right: -10px;">
                        <input type="text"  name="contractName" lay-verify="required|phone" autocomplete="off" class="layui-input contractName">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red;">*</span>承包单位：</label>
                <div class="layui-input-block" style="width: 250px;">
                    <select name="contractor" lay-verify="required" class="contractor">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red;">*</span>业务分类：</label>
                <div class="layui-input-block" style="width: 250px;">
                    <select name="codeName" lay-verify="required" class="codeName">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">编号预览：</label>
                    <div class="layui-input-inline" style="width: 250px;margin-right: -10px;">
                        <input type="text"  id="duplication" lay-verify="required|phone" autocomplete="off" class="layui-input" disabled>
                    </div>
                </div>
            </div>
            <div class="btn">
                <button type="button"  class="layui-btn layui-btn-normal" id="duplication2"  readonly="readonly">确认并复制编号</button>
                <button type="button" class="layui-btn layui-btn-normal clear" >重新编号</button>
            </div>
        </form>
    </div>
</body>
</html>
<script>
    layui.use(['form','table','layer'], function() {
        var $ = layui.jquery
            , form = layui.form
            ,layer=layui.layer;
        //承包单位
        $.ajax({
            url:'/code/getCode',
            dataType:'json',
            type:'get',
            data:{
                parentNo:'CONTRACT_UNIT',
            },
            success:function(res){
                var obj = res.obj
                var str = ''
                for (var i = 0; i < obj.length; i++) {
                    str += '<option value="' + obj[i].codeNo + '">' + obj[i].codeName + '</option>'
                }
                $('.contractor').append(str)
                form.render('select');
            }
        })

        //业务分类
        $.ajax({
            url:'/code/getCode',
            dataType:'json',
            type:'get',
            data:{
                parentNo:'BUSINESS_TYPE_CODE',
            },
            success:function(res){
                var obj = res.obj
                var str = ''
                for (var i = 0; i < obj.length; i++) {
                    str += '<option value="' + obj[i].codeNo + '">' + obj[i].codeName + '</option>'
                }
                $('.codeName').append(str)
                form.render('select');
            }
        })
        $('#duplication2').click(function () {
            if($('.contractName').val()==""){
                layer.msg('请填写合同名称', {icon: 2});
                return false
            }
            if($('.contractor').val()==""){
                layer.msg('请填写承包单位', {icon: 2});
                return false
            }
            if($('.codeName').val()==""){
                layer.msg('请填写业务分类', {icon: 2});
                return false
            }
            $.ajax({
                url:'/ContractNo/insertContractNo',
                dataType:'json',
                type:'get',
                data:{
                    contractType:1,
                    contractName:$('.contractName').val(),
                    doUnit:$('.contractor').val(),
                    do2Unit:$('.contractor').val(),
                    businessType:$('.codeName').val()
                },
                success:function(res){
                    $('#duplication').val(res.object)
                }
            })
        })

        $('.clear').click(function () {
            $('#duplication').val('')
        })
    })

</script>
